// gui/GuiComponent.h

#ifndef _GUI_GuiComponent_H_
#define _GUI_GuiComponent_H_

#ifndef _CORE_std_H_
#include <core/std.h>
#endif

#ifndef _GFX_Frame_H_
#include <gfx/Frame.h>
#endif

namespace GFX
{
	class Frame;
	class Visual;
};

struct IRenderingEngine;

namespace GUI
{

class GuiComponent
{
public:

	GuiComponent();
	virtual ~GuiComponent() {}

	virtual TypeId			GetTypeId() const = 0;
	static TypeId			GetStaticTypeId() {
		return s_TypeId;
	}

	void				SetupGuiComponent( const CORE::String & strName, bool bActive = true );

	// Accessors
	const CORE::String &	GetName() const {
		return m_strName;
	}

	GFX::Visual *			GetVisual() {
		return m_pVisual;
	}
	void					SetVisual( GFX::Visual * pVisual, bool bMakeVisible = true );

	GFX::Frame &			GetFrame() {
		return m_Frame;
	}

	bool					IsVisible() const {
		return m_bVisible;
	}
	virtual void			SetVisible( bool bVisible ) {
		m_bVisible = bVisible;
	}

	bool					IsActive() const {
		return m_bActive;
	}
	virtual void			SetActive( bool bActive ) {
		m_bActive = bActive;
	}

	uint32_t				GetId() const {
		return m_u32Id;
	}

	Math::vec3				GetLocalPosition() const {
		return m_Frame.GetLocalPosition();
	}
	Math::vec3				GetWorldPosition() const {
		return m_Frame.GetWorldMatirx().GetTransform();
	}
	void					SetPosition( const Math::vec3 & vPos ) {
		m_Frame.SetLocalPosition(vPos);
	}

	// APIs
	virtual void			Update( CORE::Time & TimeDelta ) = 0;
	virtual void			Render( IRenderingEngine * pRenderer );

private:

	static TypeId		s_TypeId;

	CORE::String		m_strName; // unique name
	uint32_t			m_u32Id; // unique id
	GFX::Frame			m_Frame;
	GFX::Visual *		m_pVisual;

	bool				m_bActive;

	bool				m_bVisible;
};

// inline Functions
inline GuiComponent::GuiComponent()
	: m_u32Id(0)
	, m_pVisual(0)
	, m_bVisible(false)
	, m_bActive(true)
{
}

inline void GuiComponent::SetVisual( GFX::Visual * pVisual, bool bMakeVisible )
{
	m_pVisual = pVisual;

	if (bMakeVisible)
	{
		SetVisible(true);
	}
}

}; // namespace GUI

#endif // _GUI_GuiComponent_H_